import { request } from '../../../api/request.js'
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    feedback: '',
    phonenum: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) { },
  //问题反馈
  feedback(e) {
    this.setData({
      feedback: e.detail.value
    })

    console.log(e)
  },
  // 手机号
  phonenum(e) {
    this.setData({
      phonenum: e.detail.value
    })
    console.log(e.detail.value)
  },
  // 确认提交
  submint() {
    request({
      url: "/user/feedback",
      data: {
        content: this.data.feedback,
        phone: this.data.phonenum
      }
    }).then(res => {
      if (res.code !== 0 || this.data.feedback == '') {
        return Toast.fail("提交失败,请填写问题内容");
      }
      Toast.success("提交成功,谢谢反馈")
      let time = setTimeout(() => {
        wx.navigateBack({
          delta: -1,
          success: (res => {
            console.log(res)
            if (res.errMsg == "navigateBack:ok") {
              clearTimeout(time)
            }
          })
        })
      }, 2000)
    }).catch(() => {
      Toast.fail("提交失败,请填写问题内容");
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
